package cc.uncarbon.module.appapi.web.app;

import cc.uncarbon.framework.core.constant.HelioConstant;
import cc.uncarbon.framework.core.page.PageParam;
import cc.uncarbon.framework.core.page.PageResult;
import cc.uncarbon.framework.web.model.request.IdsDTO;
import cc.uncarbon.framework.web.model.response.ApiResult;

import cc.uncarbon.module.appapi.constant.AppApiConstant;
import cc.uncarbon.module.appapi.model.request.AdminBookBydInsertOrUpdateDTO;
import cc.uncarbon.module.appapi.model.request.AdminBookBydListDTO;

import cc.uncarbon.module.appapi.model.response.BydBO;
import cc.uncarbon.module.appapi.model.vo.BydVO;
import cc.uncarbon.module.appapi.service.BookBydService;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * 后台管理-加油记录管理接口
 */

@Tag(name = "加油记录管理接口")
@RequestMapping(AppApiConstant.HTTP_API_URL_PREFIX + "/api/v1")
@RequiredArgsConstructor
@RestController
@Slf4j
public class AdminBookBydController {

    // 功能权限串前缀
    private static final String PERMISSION_PREFIX = "BookByd:";

    private final BookBydService bookBydService;



    @Operation(summary = "列表")
    @GetMapping("/book/byd/list")
    public ApiResult<BydVO> list() {
        return ApiResult.data(bookBydService.appList());
    }


    @Operation(summary = "详情")
    @GetMapping(value = "/book-byds/{id}")
    public ApiResult<BydBO> getById(@PathVariable Long id) {
        return ApiResult.data(bookBydService.getOneById(id, true));
    }


    @Operation(summary = "新增")
    @PostMapping("/book/byd/insert")
    public ApiResult<Void> insert(@RequestBody @Valid AdminBookBydInsertOrUpdateDTO dto) {
        bookBydService.adminInsert(dto);
        return ApiResult.success();
    }


    @Operation(summary = "编辑")
    @PutMapping(value = "/book-byds/{id}")
    public ApiResult<Void> update(@PathVariable Long id, @RequestBody @Valid AdminBookBydInsertOrUpdateDTO dto) {
        dto.setId(id);
        bookBydService.adminUpdate(dto);
        return ApiResult.success();
    }


    @Operation(summary = "删除")
    @DeleteMapping("/book-byds")
    public ApiResult<Void> delete(@RequestBody @Valid IdsDTO<Long> dto) {
        bookBydService.adminDelete(dto.getIds());
        return ApiResult.success();
    }

}
